import { Component, OnInit,Output,Input,EventEmitter } from '@angular/core';
const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) };
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
import { Router } from '@angular/router';
import { NzModalRef, NzFormatEmitEvent, NzModalService, NzTreeComponent, NzTreeNodeOptions, NzMessageService } from 'ng-zorro-antd';
import { PagesService } from '../../services/pages.service';
import { UtilService } from '../../services/util.service';
import { RequestService } from '../../services/request.service';
declare var layui: any;
declare var layer: any;
declare var $: any;

@Component({
  selector: 'app-pur',
  templateUrl: './pur.component.html',
  styleUrls: ['./pur.component.scss']
})
export class PurComponent implements OnInit {

  constructor(public router: Router, private http: HttpClient, public interfaceService: PagesService, public utilService: UtilService,public request:RequestService) {
    
  }

  @Output()  private  outer=new EventEmitter();
  @Input() puc_msg:any; 

  field1 = []     //table表格1-主表列字段集合
  data1 = {}      //table表格1-主表对象数据集合
  data1_dis = {}  //table表格1-主表对象禁用集合
  data1_sel = []  //table表格1-主表下拉框数据集合
  data1_att = []  //table表格1-主表自定义属性数据集合
  data1_selValue={} //table表格1-主表下拉框默认赋值集合
  /**
   * 表格字段动态列集合生成
   */
  filed_tablelist() {
    this.interfaceService.postPage("/erp/common/fields/getfieldsbytype", { "type":"purchase.PuoVo" }).subscribe((data: any) => {
      if (this.interfaceService.codeValidation(data)) {
      if(data.code==200){
        this.field1=this.utilService.filed_list4(data.object);
        this.popup01_table()      
      }
    }
    });
  }

  progress_list;
  pucType_list;
  acReqd_list;
  prcSite_list;
  isCms_list;
  drDiffJgd_list;
  multiImpl_list;
  implByIns_list;
  puBrdgMode_list;
  isPuItmd_list;
  isSpot_list;
  psStlMthd_list;
  splEnabled_list;
  rqdCtrl_list;
  gmEnabled_list;
  bxiEnabled_list;
  mfzEnabled_list;
  psMfzSite_list;
  planCtrl_list;
  srcDocType_list;
  ordType_list;
  delivMthd_list;
  psaCtlr_list;
  slcAutoGen_list;
  slcAutoChk_list;
  pucAutoGen_list;
  slcGen_list;
  pucAutoChk_list;
  isSlItmd_list;
  effective_list;
  suspended_list;
  cancelled_list;
  renewed_list;
  slCtrl_list;
  slFwdd_list;
  
  vdrInvd_list;

  ngOnInit() {
    this.filed_tablelist()
    setTimeout(()=>{ 
      this.interfaceService.postPage("/erp/purchase/puc/option", {}).subscribe((data0: any) => {//手动下拉
        if (this.interfaceService.codeValidation(data0)) {
        if (data0.code == 200) {
          var sele = data0.object;
          this.progress_list = sele.progress;//进度
          /* this.pucType_list = sele.pucType;//采购合同类别
          this.acReqd_list = sele.acReqd;//绑定附加成本
          this.prcSite_list = sele.prcSite;//定价点
          this.isCms_list = sele.isCms;//是否代销
          this.drDiffJgd_list = sele.drDiffJgd;//差异裁定方
          this.multiImpl_list = sele.multiImpl;//多次执行
          this.implByIns_list = sele.implByIns;//按指令执行
          this.puBrdgMode_list = sele.puBrdgMode;//采购桥接方式
          this.isPuItmd_list = sele.isPuItmd;//是否居间采购
          this.isSpot_list = sele.isSpot;//是否现货
          this.psStlMthd_list = sele.psStlMthd;//结算方式
          this.splEnabled_list = sele.splEnabled;//允许增补商品
          this.rqdCtrl_list = sele.rqdCtrl;//货期控制
          this.gmEnabled_list = sele.gmEnabled;//启用保证金
          this.bxiEnabled_list = sele.bxiEnabled;//启用配码
          this.mfzEnabled_list = sele.mfzEnabled;//启用冻款
          this.psMfzSite_list = sele.psMfzSite;//冻款点
          this.planCtrl_list = sele.planCtrl;//计划控制
          this.srcDocType_list = sele.srcDocType;//原始单据类别
          this.ordType_list = sele.ordType;//订单类别
          this.delivMthd_list = sele.delivMthd;//送货方式
          this.psaCtlr_list = sele.psaCtlr;//控制协议方
          this.slcAutoGen_list = sele.slcAutoGen;//销售合同自动生成
          this.slcAutoChk_list = sele.slcAutoChk;//销售合同自动审核
          this.pucAutoGen_list = sele.pucAutoGen;//采购合同自动生成
          this.slcGen_list = sele.slcGen;//销售合同已生成
          this.pucAutoChk_list = sele.pucAutoChk;//采购合同自动审核
          this.isSlItmd_list = sele.isSlItmd;//是否居间销售
          this.effective_list = sele.effective;//已生效
          this.suspended_list = sele.suspended;//挂起
          this.cancelled_list = sele.cancelled;//撤销
          this.renewed_list = sele.renewed;//已递延
          this.slCtrl_list = sele.slCtrl;//销售控制
          this.slFwdd_list = sele.slFwdd;//已转销
          this.vdrInvd_list=sele.vdrInvd;//供应商是否介入 */
        }
      }
      });
    },500);
  }

  unitStatus_list=JSON.parse(localStorage.getItem("unitStatus_list"))
  prodStatus_list=JSON.parse(localStorage.getItem("prodStatus_list"))
  popup01_url='';
  popup01_switchUnitId='';
  popup01 = false;
  popup01_show(url,switchUnitId?): void {
    this.popup01_url=url
    this.popup01_switchUnitId=switchUnitId;
    this.popup01 = true;
    this.popup01_table();
  }
  popup01_hide(): void {
    this.popup01 = false;
    this.popup01_url='';
    this.popup01_ss1='';
    this.popup01_ss2='';
    this.popup01_ss3=''; 
    this.popup01_ss4=''; 
    this.popup01_ss5 = '';
    this.popup01_ss6 = '';
    this.popup01_ss7 = null;
  }

  venderIdss='';
  popup01_ss1='';
  popup01_ss2='';
  popup01_ss3='';
  popup01_ss4='';
  popup01_ss5 = '';
  popup01_ss6 = '';
  popup01_ss7 = null;
  popup01_table(){
    this.popup01_listTable(this.popup01_url+"&pucNum=" + this.popup01_ss1 + "&startTime=" + this.popup01_ss2 + "&endTime=" + this.popup01_ss3 + "&venderCode=" + this.popup01_ss4+ "&vdrWarehCode=" + this.popup01_ss5+ "&vdeWarehCode=" + this.popup01_ss6+ "&progress=" + this.popup01_ss7);
  }
  indexTableId = 'popup01_tblist_pur'
  popup01_listTable(url):void{
    setTimeout(()=>{ 
      layui.use(['table',  'laydate'], (obj)=>{
        var  table = layui.table,  laydate = layui.laydate;
        laydate.render({
          elem: '#popup01_ss2' 
          ,done: (value) => {
            this.popup01_ss2=value; 
          }
        });
        laydate.render({
          elem: '#popup01_ss3' 
          ,done: (value) => {
            this.popup01_ss3=value; 
          }
        });
        var tab = this.utilService.getTable(url, "#" + this.indexTableId, this.field1)
        tab["title"] = '采购单弹窗数据表'
        table.render(tab);
        table.on('rowDouble(popup01_tblist_pur)', (obj)=>{
          this.popup01_hide();
          this.outer.emit(obj.data)       
         });
        
      });
      
    },50);
  
  }




  popup5_id;
  popup5 = false;
  popup5_show(id): void {
    this.popup5_id=id;
    this.popup5 = true;
    this.popup5_table();
  }
  popup5_hide(): void {
    this.popup5 = false;
    this.popup5_ss1='';
    this.popup5_ss2='';
    this.popup5_ss3=''; 
    this.popup5_ss4=''; 
  }

  popup5_ss1='';
  popup5_ss2='';
  popup5_ss3='';
  popup5_ss4='';
  popup5_table(){
    this.popup5_listTable("/erp/unit/option/unitOption"+"?1=1&unitType=VD&unitCode="+this.popup5_ss1+"&unitName="+this.popup5_ss2+"&inputCode="+this.popup5_ss3+"&unitStatus="+this.popup5_ss4+ "&switchUnitId=" + this.popup01_switchUnitId);
  }

  popup5_listTable(url):void{
    setTimeout(()=>{ 
      layui.use(['table'], (obj)=>{
        var  table = layui.table
        
        table.render({
          elem: '#popup5_tblist_pur'
          ,height: this.utilService.height
          ,width:680
          ,url: url
          ,page: true //开启分页
          ,limit:1000
          ,limits:this.utilService.limits
          ,title: '数据表'
          ,cellMinWidth: 100
          ,cols: [[
			{title: '序号', type: 'numbers',fixed: 'left'},
            {field: 'unitCode', title: '组织代码', sort: true}
			  ,{field: 'unitId', title: '组织id',hide:true} 
			  ,{field: 'unitName', title: '组织名称'} 
			  ,{field: 'inputCode', title: '助记码'}
			  ,{field: 'telNum', title: '电话号码'}
			  ,{field: 'address', title: '地址'}
			  ,{field: 'lmCode', title: '联系人姓名'}
			  ,{field: 'unitStatus', title: '组织状态',
				templet: (d) => {
				  return this.utilService.table_select(d.unitStatus, this.unitStatus_list);
				}
			  }
            ]]
          ,request: {
            pageName: 'page' //页码的参数名称，默认：page
            ,limitName: 'size' //每页数据量的参数名，默认：limit
          }
          ,parseData: function(res){ //res 即为原始返回的数据
            return {
              "code": res.code, //解析接口状态
              "msg": res.message, //解析提示文本
              "count": res.object.total, //解析数据长度
              "data": res.object.list //解析数据列表
            }
          }
          ,response: {
            statusCode: 200 //规定成功的状态码，默认：0
            ,dataName: 'data' //规定数据列表的字段名称，默认：data
          } 
        });
        table.on('rowDouble(popup5_tblist_pur)', (obj)=>{
          if(this.popup5_id==1){
            this.venderIdss=obj.data.unitId;
            this.popup01_ss4=obj.data.unitCode;
            this.popup5_hide();
          }
          
         });
        
      });
      
    },50);
  
  }



  popup6_url;
  popup6_id;
  popup6 = false;
  popup6_show(id): void {
    this.popup6_url="/erp/unit/option/unitOption?1=1";
    this.popup6_id=id;
    if(id==8){//搜索供应商仓库编号
      if(this.utilService.patrn.test(this.venderIdss)){//搜索选择了供应商就取供应商id
        this.popup6_url=this.popup6_url+"&unitType=WH&ownerId="+this.venderIdss;
      }else{//否则取组织id
        this.popup6_url=this.popup6_url+"&unitType=WH&ownerId="+localStorage.getItem("ownerId")
      }
    }else if(id==9){//搜索采购商仓库编号
      this.popup6_url=this.popup6_url+"&unitType=WH&ownerId="+localStorage.getItem("ownerId")
    }
    this.popup6 = true;
    this.popup6_table();
  }
  popup6_hide(): void {
    this.popup6 = false;
    this.popup6_ss1='';
    this.popup6_ss2='';
    this.popup6_ss3=''; 
    this.popup6_ss4=''; 
  }

  popup6_ss1='';
  popup6_ss2='';
  popup6_ss3='';
  popup6_ss4='';
  popup6_table(){
    this.popup6_listTable(this.popup6_url+"&unitCode="+this.popup6_ss1+"&unitName="+this.popup6_ss2+"&inputCode="+this.popup6_ss3+"&unitStatus="+this.popup6_ss4+ "&switchUnitId=" + this.popup01_switchUnitId);
  }

  popup6_listTable(url):void{
    setTimeout(()=>{ 
      layui.use(['table'], (obj)=>{
        var  table = layui.table
        
        table.render({
          elem: '#popup6_tblist_pur'
          ,height: this.utilService.height
          ,width:680
          ,url: url
          ,page: true //开启分页
          ,limit:1000
          ,limits:this.utilService.limits
          ,title: '数据表'
          ,cellMinWidth: 150
          ,cols: [[
			{title: '序号', type: 'numbers',fixed: 'left'},
            {field: 'unitCode', title: '组织代码', sort: true}
			  ,{field: 'unitId', title: '组织id',hide:true} 
			  ,{field: 'unitName', title: '组织名称'} 
			  ,{field: 'inputCode', title: '助记码'}
			  ,{field: 'telNum', title: '电话号码'}
			  ,{field: 'address', title: '地址'}
			  ,{field: 'lmCode', title: '联系人姓名'}
			  ,{field: 'unitStatus', title: '组织状态',
				templet: (d) => {
				  return this.utilService.table_select(d.unitStatus, this.unitStatus_list);
				}
			  }
            ]]
          ,request: {
            pageName: 'page' //页码的参数名称，默认：page
            ,limitName: 'size' //每页数据量的参数名，默认：limit
          }
          ,parseData: function(res){ //res 即为原始返回的数据
            return {
              "code": res.code, //解析接口状态
              "msg": res.message, //解析提示文本
              "count": res.object.total, //解析数据长度
              "data": res.object.list //解析数据列表
            }
          }
          ,response: {
            statusCode: 200 //规定成功的状态码，默认：0
            ,dataName: 'data' //规定数据列表的字段名称，默认：data
          } 
        });
        table.on('rowDouble(popup6_tblist_pur)', (obj)=>{
          this.popup6_hide();
          if(this.popup6_id==8){
            this.popup01_ss5=obj.data.unitCode;
          }else if(this.popup6_id==9){
            this.popup01_ss6=obj.data.unitCode;
          }
         });
        
      });
      
    },50);
  
  }













}
